package com.iemes.controller.hr;
/**
 * 餐费统计
 */
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.DepartmentForMap;
import com.iemes.entity.DockFormMap;
import com.iemes.entity.MealFormMap;
import com.iemes.entity.StaffFormMap;
import com.iemes.mapper.hr.DepartmentinfoMapper;
import com.iemes.mapper.hr.DinerMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;
@Controller
@RequestMapping("/hrdiner/")
public class DinerController extends BaseController{
	
	@Inject
	private DepartmentinfoMapper departmentinfoMapper;
	@Inject
	private DinerMapper dinerMapper;
	//用餐统计页面
		@RequestMapping("dinerAttend")
		public String examineOrder(Model model){
			DepartmentForMap departmentForMap=getFormMap(DepartmentForMap.class);
			departmentForMap.put("where", "where id!=16 ");
			//查部门名称
			List<DepartmentForMap> department=departmentinfoMapper.findByWhere(departmentForMap);
	        model.addAttribute("caset",department);
			model.addAttribute("res", findByRes());
			return Common.BACKGROUND_PATH + "/hr/diner_list";
		}
		//用餐统计分页
		@ResponseBody
		@RequestMapping("diner_findByPage")
		public PageView findByPage(String pageNow, String pageSize) throws Exception 
		{   
			MealFormMap mealFormMap=getFormMap(MealFormMap.class);
			List<Map<String,Object>> mealFormMaps=dinerMapper.getAllDiner(mealFormMap);
              LuogicPaging(pageNow, pageSize, mealFormMaps);
			pageView.setRecords(mealFormMaps);
			return pageView;
		}

		//编辑餐费信息
		@RequestMapping("diner_edit")
		public String editUI(Model model) throws Exception {
			String id = getPara("id");
			if(Common.isNotEmpty(id)){ 
				//查询餐费
				MealFormMap mealFormMap=dinerMapper.findbyFrist("id", id,MealFormMap.class);
				//通过餐费查询收费表
				DockFormMap dockFormMap=dinerMapper.findbyFrist("meal_id", id, DockFormMap.class);
				String peopleID=dockFormMap.get("person_id").toString();
				//通过收费表查询人员信息
				StaffFormMap staffFormMap=dinerMapper.findbyFrist("id", peopleID, StaffFormMap.class);
				model.addAttribute("meal",mealFormMap);
				model.addAttribute("dock",dockFormMap);
				model.addAttribute("staff",staffFormMap);
			}

			return Common.BACKGROUND_PATH + "/hr/diner_edit";
		}
		//修改餐费信息
		@ResponseBody
		@RequestMapping(value="diner_editEntity")
		@SystemLog(module="餐费数据维护",methods="查看餐费-修改餐费")//凡需要处理业务逻辑的.都需要记录操作日志
		public String editEntity() {		
			MealFormMap mealFormMap = getFormMap(MealFormMap.class);
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String timess=df.format(new Date());
			try {
				mealFormMap.put("record_date", timess);
				dinerMapper.editEntity(mealFormMap);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return "false";
			}
			return "success";
		}

		
		
		
}
